home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Program to test Code download subroutine
-
- Written by: Anumele D. Raja
-
- Date: May 6, 1988
-
- Last modified: April 10, 1989
-
- */
-
- /* Main includes */
-
- #include <Types.h> /* Nearly always required */
- #include <Quickdraw.h> /* to access the qd globals */
- #include <Fonts.h> /* for InitFonts() and possible use of fonts */
- #include <Resources.h> /* resource file calls */
- #include <Events.h> /* very important for multi-tasking under multi finder */
- #include <Windows.h> /* window manager calls */
- #include <Controls.h> /* control manager calls */
- #include <Dialogs.h> /* dialog manager calls */
- #include <Menus.h> /* menu manager calls */
- #include <TextEdit.h> /* text editor */
- #include <Packages.h> /* standard file package */
- #include <Strings.h> /* include for debugger */
- #include <Stdio.h> /* standard I/O routines */
- #include <Files.h> /* file manager equates */
- #include <OSEvents.h> /* OS events */
- #include <SysEqu.h> /* Sys equates for CurDirStore */
- #include <ToolUtils.h> /* Tools utilities like LoWord/HiWord */
-
- #include "os.h"
- #include "arose.h"
-
- #include "siop.h"
- #include "download.h"
-
- Point inpLocn = {50, 50};
- SFTypeList typeList = {'TEXT'};
-
- #define NIL 0
- #define TRUE 0xff
- #define FALSE 0x00
- #define firstTime -1
- #define nullEvent 100
- #define DLOG_ERR 130
- #define continueButton 1
-
- #define NoOfItems 21
-
- short option, volRefNum;
- short slotNUM;
- short slotMask;
- Boolean slotFlag[6]; /* maximum number of downloadable slots is 6 */
- short slotGood[6];
- char hiliteDownload;
- char rsrcPut;
- short errCode;
- SFReply reply;
-
- char resTypeStr[5]="CODE";
- char PrevRsrc[5] = "CODE";
- Boolean Cancel = FALSE;
-
- DialogPtr mainDlg;
-
- pascal short myDlgHook(short, DialogPtr);
- void SetupResource(DialogPtr, char *);
-
- long cnvhex();
- void startMCPHW();
- void startASTHW();
-
- void stopMCPHW();
- void stopASTHW();
-
- pascal void ProgProc(long segSize);
-
- unsigned long AST_FindRAMLength();
- unsigned long MCP_FindRAMLength();
-
- /* Error messages */
-
- char errMsg[][32] = {
- "\pNo Error", /* 0 */
- "\pNo Jump Table Found", /* 1 */
- "\pBad Data Init Segment", /* 2 */
- "\pGlobal Data Format Error", /* 3 */
- "\pCode Segment Error", /* 4 */
- "\pCan run only on Mac II", /* 5 */
- "\pInvalid Slot", /* 6 */
- "\pSlot specified is empty", /* 7 */
- "\pCould not open Resource File", /* 8 */
- "\pDownload file is wrong type", /* 9 */
- "\pStarting error", /* 10 */
- "\pNo memory", /* 11 */
- "\pRSM Error", /* 12 */
- "\pNo RSM", /* 13 */
- "\pNo A/ROSE running on slot", /* 14 */
- "\pNo 'CNFG' resource", /* 15 */
- "\pNo A/ROSE Prep File", /* 16 */
- "\pYou are exiting download", /* 17 */
- "\pNo slot selected for download", /* 18 */
- "\pDownloading is successful" /* 19 */
- };
-
- main()
- {
- struct ST_Registers regs;
- short refNum, slotSel, slot, i;
- Handle dlogRes;
- DialogTPtr dlogPtr;
- short status;
-
- /* Initialize managers */
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- InitCursor();
-
- TEInit();
- InitDialogs(NULL);
-
- NewFindcard(&slotMask, 0);
-
- dlogRes = GetResource('DLOG', 128); /* update resource with refNum */
- dlogPtr = (DialogTPtr)*dlogRes;
- *(long *)CurDirStore = dlogPtr->refCon;
- ChangedResource(dlogRes);
-
- errCode = 0;
-
- for (i=0; i<6; i++) { /* set flags for check boxes */
- slotFlag[i] = FALSE;
- }
-
- slotSel = 0;
- option = 0;
-
- while (!Cancel) {
- hiliteDownload = FALSE;
- rsrcPut = FALSE;
-
- sfpgetfile(&inpLocn, "File Name:", NIL, -1, typeList, myDlgHook, &reply, 128, NIL);
- if (!Cancel) {
-
- if ((refNum = OpenRFPerm(reply.fName, reply.vRefNum, fsRdPerm)) != -1) {
- slotSel = 0;
- for (i=0; i<6; i++) {
- if (slotFlag[i])
- slotSel |= 1<<(i+9);
- }
- status = 18; /* Say no card is selected */
- for (slot=0; slot<16; slot++) {
- if ((1<<slot) & slotSel) {
- slotNUM = slot;
- if (!option) {
- HaltCard(slotNUM);
- status = NewDownload(slotNUM, DEF_ADDROFFSET, DEF_LOADADDR, (struct gCommon *)0x400,
- option?0:DL_INITLOAD|DL_CLEARMEM,
- (ResType)*((long *)resTypeStr), ®s, 0);
- StartCard(slotNUM);
- }
- else {
- status = NewDownload(slotNUM, 0, 0, (struct gCommon *)0x400, 0, (ResType)*((long *)resTypeStr), ®s, 0);
- }
- }
- }
- CloseResFile(refNum);
-
- dlogRes = GetResource('DLOG', 128); /* update resource with refNum */
- dlogPtr = (DialogTPtr)*dlogRes;
- dlogPtr->refCon = *(long *)CurDirStore;
- ChangedResource(dlogRes);
- }
- else
- status = DLE_FILEWRONG;
- }
- else
- status = DLE_ABORT;
-
- if (status != DLE_NOERR) {
- errCode = status;
- }
- else {
- errCode = 19;
- }
- }
- }
-
- struct itemTbl {
- short itemNo;
- struct radItem *itmPtr;
- };
-
- struct radItem {
- short riValue;
- struct radDesc *radPtr;
- };
-
- struct radDesc {
- short *radValPtr;
- short radNoItems;
- short *radItems;
- };
-
- short radListOption[] = { 11, 12 };
-
- struct radDesc radOption = { &option, sizeof(radListOption)/sizeof(short), radListOption };
-
- struct radItem initLoad = { 0, &radOption };
- struct radItem dynLoad = { 1, &radOption };
-
- struct itemTbl itemTbl[] = {
- {11, &initLoad}, {12, &dynLoad},
- {13, &slotFlag[0]}, {14, &slotFlag[1]}, {15, &slotFlag[2]}, {16, &slotFlag[3]},
- {17, &slotFlag[4]}, {18, &slotFlag[5]}, {23, &resTypeStr}
- };
- short cardItem[6] = { 13, 14, 15, 16, 17, 18 };
-
- pascal short myDlgHook(item, myDialog)
- short item;
- DialogPtr myDialog;
- {
- short itemType, i, j, menuID, noOfRsrcTypes, codeNum, refNum;
- long result;
- Handle control;
- Rect box, tempRect, popUpTitleRect;
- Point menuPt;
- MenuHandle popUpMenu;
- char resStr[5];
- WDPBRec paramBlock;
- void MakeDownloadBold(DialogPtr);
-
- mainDlg = myDialog;
- if (item == firstTime) {
-
- for (i=0; i<sizeof(itemTbl)/sizeof(struct itemTbl); i++) {
- GetDItem(myDialog, itemTbl[i].itemNo, &itemType, &control, &box);
- switch (itemType) {
- case ctrlItem+chkCtrl:
- for (j=0; j<6; j++) {
- if (cardItem[j] == itemTbl[i].itemNo) {
- if (slotMask & (1<<(j+9)))
- HiliteControl((ControlHandle)control, 0);
- else
- HiliteControl((ControlHandle)control, 255);
- }
- }
- if (*(Boolean *)itemTbl[i].itmPtr)
- SetCtlValue((ControlHandle)control, 1);
- else
- SetCtlValue((ControlHandle)control, 0);
- break;
- case ctrlItem+radCtrl:
- for (j=0; j<(itemTbl[i].itmPtr)->radPtr->radNoItems; j++) {
- GetDItem(myDialog, (itemTbl[i].itmPtr)->radPtr->radItems[j], &itemType, &control, &box);
- SetCtlValue((ControlHandle)control, 0);
- }
- GetDItem(myDialog, radListOption[option], &itemType, &control, &box);
- SetCtlValue((ControlHandle)control, 1);
- break;
- case statText:
- SetupResource(myDialog, resTypeStr);
- break;
- default:
- break;
- }
- }
- }
- else if (item == nullEvent) {
- if (!hiliteDownload) {
- MakeDownloadBold(myDialog);
- hiliteDownload = TRUE;
- }
- else {
- if (!rsrcPut) {
- SetupResource(myDialog, resTypeStr);
- if (errCode) {
- GetDItem(mainDlg, 21, &itemType, &control, &box);
- SetIText(control, errMsg[errCode]);
- }
- rsrcPut = TRUE;
- }
- }
- }
- else {
- if (item == 1) {
- for (i=0; i<sizeof(itemTbl)/sizeof(struct itemTbl); i++) {
- GetDItem(myDialog, itemTbl[i].itemNo, &itemType, &control, &box);
- if (itemType == editText) {
- getitext(control, (char *)itemTbl[i].itmPtr);
- }
-
- }
- Cancel = FALSE;
- }
- else {
-
- GetDItem(mainDlg, 21, &itemType, &control, &box);
- SetIText(control, "\p ");
-
- for (i=0; i<sizeof(itemTbl)/sizeof(struct itemTbl); i++) {
- if (item == itemTbl[i].itemNo) {
- GetDItem(myDialog, item, &itemType, &control, &box);
- switch (itemType) {
- case ctrlItem+chkCtrl:
- if (*(Boolean *)itemTbl[i].itmPtr = !*(Boolean *)itemTbl[i].itmPtr)
- SetCtlValue((ControlHandle)control, 1);
- else
- SetCtlValue((ControlHandle)control, 0);
- break;
- case ctrlItem+radCtrl:
- for (j=0; j<itemTbl[i].itmPtr->radPtr->radNoItems; j++) {
- GetDItem(myDialog, itemTbl[i].itmPtr->radPtr->radItems[j], &itemType, &control, &box);
- SetCtlValue((ControlHandle)control, 0);
- }
- GetDItem(myDialog, item, &itemType, &control, &box);
- SetCtlValue((ControlHandle)control, 1);
- *(itemTbl[i].itmPtr->radPtr->radValPtr) = (itemTbl[i].itmPtr)->riValue;
- break;
- case statText:
- menuID = UniqueID('MENU');
- popUpMenu = NewMenu(menuID, "\pResource Type");
- InsertMenu(popUpMenu, -1);
- resStr[0] = 4;
- codeNum = 1;
-
- paramBlock.ioCompletion = 0;
- paramBlock.ioNamePtr = 0;
- paramBlock.ioVRefNum = 0;
- paramBlock.ioWDProcID = 0;
- paramBlock.ioWDDirID = *(long *)CurDirStore;
- PBOpenWD(¶mBlock, FALSE);
-
-
- if ((refNum = OpenRFPerm(reply.fName, paramBlock.ioVRefNum, fsRdPerm)) != -1) {
- noOfRsrcTypes = Count1Types();
- if (noOfRsrcTypes > 32) {
- GetDItem(mainDlg, 21, &itemType, &control, &box);
- SetIText(control, "\pToo many Resources in this file");
- }
- else {
-
- for (j=1; j<=noOfRsrcTypes; j++) {
- Get1IndType((ResType *)(&result), j);
- if (result == *(long *)PrevRsrc)
- codeNum = j;
- resStr[1] = ((char *)&result)[0]; // Move resource to resource string
- resStr[2] = ((char *)&result)[1];
- resStr[3] = ((char *)&result)[2];
- resStr[4] = ((char *)&result)[3];
- AppendMenu(popUpMenu, resStr);
- }
-
- GetDItem(myDialog, item-1, &itemType, &control, &popUpTitleRect);
- InvertRect(&popUpTitleRect);
-
- GetDItem(myDialog, item, &itemType, &control, &box);
- tempRect = box;
- InsetRect(&tempRect, -4, -4);
- EraseRect(&tempRect);
- InsertMenu(popUpMenu, -1);
- menuPt.v = box.top;
- menuPt.h = box.left;
- LocalToGlobal(&menuPt);
-
- result = PopUpMenuSelect(popUpMenu, menuPt.v, menuPt.h, codeNum);
-
- if (LoWord(result)) {
-
- /* Process menu selection */
-
- getitem(popUpMenu, LoWord(result), resTypeStr);
-
- SetupResource(myDialog, resTypeStr);
- strcpy(PrevRsrc, resTypeStr);
- }
- else {
- SetupResource(myDialog, PrevRsrc);
- }
-
- DeleteMenu(menuID);
-
- GetDItem(myDialog, item-1, &itemType, &control, &popUpTitleRect);
- InvertRect(&popUpTitleRect);
-
- }
- CloseResFile(refNum);
- }
- break;
-
- default:
- break;
- }
- }
- }
- }
- }
- if (item == getCancel)
- Cancel = TRUE;
- return item;
- }
-
- void MakeDownloadBold(myDialog)
- DialogPtr myDialog;
- {
- GrafPtr savePort;
- PenState savePnState;
- short itemType;
- Handle control;
- Rect myRect;
- GetDItem(myDialog, 1, &itemType, &control, &myRect);
- GetPort(&savePort);
- GetPenState(&savePnState);
- SetPort(myDialog);
- PenSize(3,3);
- InsetRect(&myRect, -4, -4);
- FrameRoundRect(&myRect, 16, 16);
- SetPenState(&savePnState);
- SetPort(savePort);
- }
-
- long cnvhex(hexstr, hexlen)
- char hexstr[];
- int hexlen;
- {
- long val;
- char tmpstr[17];
- if (hexlen>16) hexlen=16;
- strncpy(tmpstr, hexstr, hexlen);
- tmpstr[hexlen] = '\0';
- sscanf(tmpstr, "%lx", &val);
- return val;
- }
-
- pascal void ProgProc(segSize)
- unsigned long segSize;
- {
- short itemType;
- char sizeStr[9];
- Handle control;
- Rect box;
- GetDItem(mainDlg, 21, &itemType, &control, &box);
- sprintf(sizeStr,"Downloading %1X with %08X bytes", slotNUM, segSize);
- setitext(control, sizeStr);
- return;
- }
-
- void SetupResource(myDialog, resTypeStr)
- DialogPtr myDialog;
- char resTypeStr[5];
- {
- PenState pnState;
- short itemType;
- Rect box, tempRect;
- Handle control;
-
- GetDItem(myDialog, 23, &itemType, &control, &box);
- tempRect = box;
- /* EraseRect(&box);
- FrameRect(&box); */
- GetPenState(&pnState);
- PenSize(1,1);
- PenMode(patCopy);
- InsetRect(&tempRect, -1, -1);
- /* RGBForeColor((RGBColor *)RGBBlack);*/
- FrameRect(&tempRect);
- tempRect.bottom += 1;
- tempRect.right += 1;
- PenSize(1,1);
- PenMode(patCopy);
- /* RGBForeColor((RGBColor *)RGBBlack);
- FrameRect(&tempRect); */
- MoveTo(tempRect.left+1, box.bottom+1);
- LineTo(box.right+1, box.bottom+1);
- LineTo(box.right+1, box.top);
- MoveTo(box.left+12, box.bottom-4);
- drawstring(resTypeStr);
- SetPenState(&pnState);
- }
-